package nl.alwinzwets.visuals
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	
	public class Bloem extends MovieClip
	{		
		public var _mc:MovieClip;
		public var bloemX:int;
		
		private var _meelA:DisplayObject;
		private var _meelV:DisplayObject;
		private var _stamper:DisplayObject;
		
		
		
		
		public function Bloem(mc:MovieClip, mcMV:MovieClip, mcMA:MovieClip, mcS:MovieClip)
		{
			_mc = mc;
			
			// constructor
			addChild(_mc);
		
			if(hasMeeldraadAchter()){
				trace("achterste");
				// Add meeldraad
				addMeeldraadAchter(_mc.hookmeelback.x,_mc.hookmeelback.y,_mc.hookmeelback.rotation,mcMA);
			}
			
			if(hasStamper()){
				// Add stamper
				addStamper(_mc.hookstamper.x,_mc.hookstamper.y,_mc.hookstamper.rotation,mcS);
			}
			
			if(hasMeeldraad()){
				// Add meeldraad
				addMeeldraad(_mc.hookmeelfront.x,_mc.hookmeelfront.y,_mc.hookmeelfront.rotation,mcMV);
			}
			
			
		}
		
		//** Stamper controller
		//--------------------------------------------------------------------------------
			
		private function hasStamper():Boolean
		{
			try {
        		_mc.hookstamper.alpha = 0;
            	return true
        	} catch (e:Error) {
				
        	}
        	return false;
		}
				
		private function addStamper(sX:int, sY:int, sR:Number, sMC:MovieClip):void
		{	
			var stamp:Stamper = new Stamper(sMC);
			_stamper = _mc.addChild(stamp);

			stamp.x = sX; 
			stamp.y = sY;
			stamp.rotation = sR;
		}

		
		//** Meeldraad controller
		//--------------------------------------------------------------------------------
			
		private function hasMeeldraad():Boolean
		{
			try {
        		_mc.hookmeelfront.alpha = 0;
            	return true
        	} catch (e:Error) {
				
        	}
        	return false;
		}
		
		private function hasMeeldraadAchter():Boolean
		{
			try {
        		_mc.hookmeelback.alpha = 0;
            	return true
        	} catch (e:Error) {
				
        	}
        	return false;
		}
				
		private function addMeeldraad(mX:int, mY:int, mR:Number, mMC:MovieClip):void
		{	
			var meel:Meeldraad = new Meeldraad(mMC);
			_meelV = _mc.addChild(meel);
			
			_mc.setChildIndex(_mc.kroonblad, 5);
			_mc.setChildIndex(_meelV, 4);
			_mc.setChildIndex(_stamper, 3);
			_mc.setChildIndex(_meelA, 2);
			
						
			meel.x = mX; 
			meel.y = mY;
			meel.rotation = mR;
		}
		
		private function addMeeldraadAchter(mX:int, mY:int, mR:Number, mMC:MovieClip):void
		{	
			var meel:Meeldraad = new Meeldraad(mMC);
			_meelA = _mc.addChild(meel);
			
			_meelA.x = mX; 
			_meelA.y = mY;
			_meelA.rotation = mR;
		}
		
		
	}
}